devfandomcom-20200223-history
Global Lua Modules/T
T''' is a feature-packed example generator for brace-based wikitext. It allows users to link to and describe templates and module invocations using familiar syntax. Installation Usage The basics At its most basic, this template creates fancy links to other templates. For example, here's how you would link to Template:Sandbox: (We'll be using Template:Sandbox throughout this tutorial, but any template will work—including T itself!) Parameter descriptions T wouldn't be very interesting if it was only able to generate links. Indeed, the template is more useful than that: it also accepts additional values after the name of the template, which are used to describe its parameters. Let's amend our previous example to include descriptions for } and }: Note that, for technical reasons, parameter descriptions must occur sequentially. In other words, these will not work: Parameter names Despite the ominous warning above, there is a way to describe named parameters with T. Simply separate the name and description with the numeric character reference =, like so: Alternately, if you've installed Template:=, then this will do the same thing: the first parameter|two the second parameter}} The latter form is preferable, since your editors are more likely to know what does than =. Blank descriptions If you leave the value of a parameter description blank, it will default to .... For example: Literal parameter values Sometimes when writing documentation, you'll want to talk about what happens when the user supplies a specific value to a parameter, rather than describing the parameter as a whole. You can do this in T by wrapping the value in single or double quotes, like so: Empty values are also possible: Note that the whole value needs to be in quotes, so this won't work: Escaping T doesn't provide any means of escaping special characters like quotes. As with all other wikitext, you can use tags instead. For example: Flags T allows you to modify how it behaves by enabling or disabling special flags. Each flag has both a longhand and a shorthand form, which are listed in the table to the right. invocation (i) Enabling the invocation flag switches T from transclusion mode, which describes a template, to invocation mode, which describes a module. These two modes are very similar, the only difference being that the latter requires the name of a function to call. For example, here's how you would link to Module:Sandbox: multiline (m) Enabling the multiline flag forces T to put each parameter, as well as the opener and closer, on its own line. For example: As a module You can also use T from within another Lua module! They're largely similar, but there are a few differences to be aware of: * There is a separate function for each mode, rather than defaulting to transclusion mode and using flags to switch to others. * Arguments must be passed in the following order: *# Any required data, e.g. the template name in transclusion mode *# (Optional.) A sequential table with parameters *# (Optional.) A table with options, e.g. the multiline flag * Shorthand flag names are not available, in order to be more explicit. * You can use a literal equals sign to separate parameter names from their descriptions (or values). Here's are a few examples of the Lua syntax: -- import the module local t = require("Dev:T") -- use `transclusion` for templates local myFirstTemplateLink = t.transclusion("Sandbox") -- parameters are the same as usual local mySecondTemplateLink = t.transclusion("Sandbox", { "a", "b=c", "'d'", }) -- flags work, too local myThirdTemplateLink = t.transclusion("Sandbox", { "a", "b=c", "'d'", }, {multiline = true}) -- use `invocation` for modules local myFirstModuleLink = t.invocation("Sandbox", "main") -- everything else is the same as `transclusion` local mySecondModuleLink = t.invocation("Sandbox", "main", { "a", "b=c", "'d'", }, {multiline = true}) Function reference transclusion Generator for transclusion syntax, e.g. . Signature ('''title: string, params: Sequence<string> | nil, options: Options | nil) -> string Parameters ; title : The name of the template to link to, without the namespace prefix. ; params : (Optional.) A sequentual table of parameters, as described above. ; options : (Optional.) A table with configuration flags, as described above. invocation Generator for invocation syntax, e.g. . Signature (title: string, func: string, params: Sequence<string> | nil, options: Options | nil) -> string Parameters ; title : The name of the module to link to, without the namespace prefix. ; func : The name of the function to call. ; params : (Optional.) A sequentual table of parameters, as described above. ; options : (Optional.) A table with configuration flags, as described above. main Entry point from the wikitext side. Determines which generator to use based on the provided arguments. Signature (frame: Frame) -> string Parameters ; frame : A frame object whose arguments will determine the correct generator to use. Changelog ; : Initial revision. Ported oldid=70019}} Template:T to Lua in order to remove its 20-parameter limitation. ; : Added named parameter syntax, e.g. }}. ; : Added the multiline flag, e.g. . ; : Added invocation mode, e.g. . ; : Completely rewrote the module to improve clarity and separation of concerns. Added p.transclusion and p.invocation for use in external Lua modules. Minor improvements to parsing and the rendered output. ; : Added literal parameter values, e.g. . Improved structure of rendered output with additional tags and metadata.